package com.twu.biblioteca.control;

import com.twu.biblioteca.library.main.Library;

import java.lang.reflect.Method;
import java.util.Scanner;

public class BibliotecaApp {

    public static void main(String[] args) throws Exception {
        new BibliotecaApp().mainMenu();
    }

    public void mainMenu() throws Exception {
        Scanner inputScanner = new Scanner(System.in);
        System.out.println(Strings.welcomeMessage);
        Library library= new Login(inputScanner).loginMenu();
        if(library == null)
            return;
        int option;
        System.out.println(Strings.selectOption);

        while(true){
            System.out.println(Strings.mainMenu);
            option = inputScanner.nextInt();
            if (option == 7){
                break;
            }
            Method methodToInvoke = new CommandControl().getMethod(option);
            if ( methodToInvoke == null) {
                System.out.println(Strings.invalidOption);
            }
            else {
                methodToInvoke.invoke(library);
            }
            System.out.println("\n\n\n");
        }
    }
}
